1 module common_macos; 2 import commons; 3 import features.git; 4 import tools.releasegame; 5 enum XCodeDFolder = "D"; 6 7 void setupPerCompiler(ref Terminal t, string compiler, string arch, out string extraLinkerFlags) 8 { 9 switch(compiler) 10 { 11 default: 12 case "auto", "ldc2": 13 { 14 string outputDruntime = getHipPath("build", "appleos", XCodeDFolder, "static", "libdruntime-ldc.a"); 15 string ldcLibPath = buildNormalizedPath(configs["ldcPath"].str, "lib-"~arch); 16 17 string druntimeLib = ldcLibPath.getFirstExisting("libdruntime-ldc.a"); 18 if(druntimeLib == null) 19 throw new Error("DRuntime Library not found on path "~configs["ldcPath"].str); 20 t.writelnSuccess("Copying druntime to XCode ", druntimeLib, " -> ", outputDruntime); 21 t.flush; 22 std.file.copy(druntimeLib, outputDruntime); 23 24 string phobosLib = ldcLibPath.getFirstExisting("libphobos2.a", "libphobos.a", "libphobos2-ldc.a"); 25 if(phobosLib == null) throw new Error("Could not find your phobos library"); 26 string outputPhobos = getHipPath("build", "appleos", XCodeDFolder,"static"); 27 std.file.mkdirRecurse(outputPhobos); 28 outputPhobos = buildNormalizedPath(outputPhobos, "libphobos2.a"); 29 30 t.writelnSuccess("Copying phobos to XCode ", phobosLib, "->", outputPhobos); 31 t.flush; 32 std.file.copy(phobosLib, outputPhobos); 33 34 extraLinkerFlags = "-ldruntime-ldc "; 35 break; 36 } 37 case "dmd": 38 { 39 string outputDruntime = getHipPath("build", "appleos", XCodeDFolder, "static", "libdruntime-ldc.a"); 40 if(std.file.exists(outputDruntime)) std.file.remove(outputDruntime); 41 42 string phobosLib = configs["phobosLibPath"].str.getFirstExisting("libphobos2.a", "libphobos.a", "libphobos2-ldc.a"); 43 if(phobosLib == null) throw new Error("Could not find your phobos library"); 44 45 string outputPhobos = getHipPath("build", "appleos", XCodeDFolder,"static"); 46 std.file.mkdirRecurse(outputPhobos); 47 outputPhobos = buildNormalizedPath(outputPhobos, "libphobos2.a"); 48 t.writelnSuccess("Copying phobos to XCode ", phobosLib, "->", outputPhobos); 49 t.flush; 50 std.file.copy(phobosLib, outputPhobos); 51 } 52 } 53 } 54 55 56 void prepareAppleOSBase(Choice* c, ref Terminal t, ref RealTimeConsoleInput input) 57 { 58 cached(() => timed(t, submoduleLoader.execute(t, input))); 59 putResourcesIn(t, getHipPath("build", "appleos", "assets")); 60 61 // executeGameRelease(t); 62 //The template may not be present 63 cached(() => timed(t, outputTemplate(t, configs["gamePath"].str))); 64 } 65 66 void cleanAppleOSLibFolder() 67 { 68 string targetDir = getHipPath("build", "appleos", XCodeDFolder, "libs"); 69 if(std.file.exists(targetDir)) 70 std.file.rmdirRecurse(targetDir); 71 std.file.mkdirRecurse(targetDir); 72 } 73 74 75 import features.ruby_gem; 76 Feature[] requiredGems; 77 78 static this() 79 { 80 requiredGems = [ 81 FeatureMakeRubyGem("xcodeproj", "Used for updating HipremeEngine.xcodeproj with the current project libraries and compiler"), 82 FeatureMakeRubyGem("json", "Used for updating HipremeEngine.xcodeproj with the current project libraries and compiler"), 83 ]; 84 85 } 86 87 void injectLinkerFlagsOnXcode(ref Terminal t, ref RealTimeConsoleInput input, string extraLinkerFlags) 88 { 89 with(WorkingDir(getHipPath("build", "appleos"))) 90 { 91 foreach(ref Feature gem; requiredGems) 92 if(!gem.getFeature(t, input)) 93 throw new Error("Gem is required for continuing building"); 94 if(t.wait(spawnShell("ruby injectLib.rb "~extraLinkerFlags)) != 0) 95 throw new Error("ruby injectLib.rb with flags "~extraLinkerFlags~" failed."); 96 } 97 } 98 99 100 private __gshared string codeSignUuid; 101 /** 102 * No need to codesign a non release version. 103 */ 104 string getCodeSignCommand(ref Terminal t, bool isReleaseVersion = false) 105 { 106 if(isReleaseVersion) 107 { 108 cached( 109 { 110 auto res = executeShell("security find-identity -v -p codesigning"); 111 if(res.status) 112 throw new Error("Could not get codesigning UUID for building to iOS"); 113 import std.string:indexOf, chomp; 114 string uuid = res.output; 115 codeSignUuid = uuid[uuid.indexOf(')')+1..uuid.indexOf('"')].chomp; 116 t.writelnHighlighted("CodeSign UUID: ", codeSignUuid); 117 }); 118 return "PROVISIONING_PROFILE='"~codeSignUuid~"' "; 119 } 120 else 121 return "CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO CODE_SIGN_ALLOWED=NO"; 122 } 123